<template>
  <router-view/>
</template>

<script lang="ts" setup>
import {RouterView} from 'vue-router'

import {usePositionStore} from '@/stores/Person/Position'
import {useLevelStore} from '@/stores/Person/Level'
import {useDepartmentStore} from '@/stores/Person/Department'
import {useDictGroupStore} from '@/stores/Person/DictGroup'
import {useHeadsStore} from '@/stores/Person/Heads'
import {getDepartmentApi, getDictGroupApi, getHeadApi, getLevelApi, getPositionApi} from '@/api/Select'

const HeadsStore = useHeadsStore()
const DictGroupStore = useDictGroupStore()
const PositionStore = usePositionStore()
const LevelStore = useLevelStore()
const DepartmentStore = useDepartmentStore()

// 请求(获取)部门表
const getDepartment = () => {
  getDepartmentApi().then(response => {
    DepartmentStore.destroyForm()
    for (let i = 0; i < response["data"].length; i++) {
      DepartmentStore.createdForm(response["data"][i])
    }
  })
}
// 请求(获取)字典类型表
const getDictGroup = () => {
  getDictGroupApi().then(response => {
    DictGroupStore.destroyForm()
    for (let i = 0; i < response["data"].length; i++) {
      DictGroupStore.createdForm(response["data"][i])
    }
  })
}
// 请求(获取)职级表
const getLevel = () => {
  getLevelApi().then(response => {
    LevelStore.destroyForm()
    for (let i = 0; i < response["data"].length; i++) {
      LevelStore.createdForm(response["data"][i])
    }
  })
}
// 初始化(获取)职位表
const getPosition = () => {
  getPositionApi().then(response => {
    PositionStore.destroyForm()
    for (let i = 0; i < response["data"].length; i++) {
      PositionStore.createdForm(response["data"][i])
    }
  })
}
// 初始化(获取)负责人表
const getHead = () => {
  getHeadApi().then(response => {
    HeadsStore.destroyForm()
    for (let i = 0; i < response["data"].length; i++) {
      HeadsStore.createdForm(response["data"][i])
    }
  })
}

// 初始化函数(确保只运行一次)
const Init = () => {
  if (!PositionStore.isExecute) {
    getPosition()
    PositionStore.execute()
  }
  if (!DepartmentStore.isExecute) {
    getDepartment()
    DepartmentStore.execute()
  }
  if (!LevelStore.isExecute) {
    getLevel()
    LevelStore.execute()
  }
  if (!DictGroupStore.isExecute) {
    getDictGroup()
    DictGroupStore.execute()
  }
  if (!HeadsStore.isExecute) {
    getHead()
    HeadsStore.execute()
  }
}
// 初始化
Init()
</script>

<style scoped>
* {
  margin: 0;
  padding: 0;
}
</style>
